import java.util.List;

/*
 * @Author: qianmingtian
 * @Date: 2020-07-07 17:37:01
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-08 08:25:42
 * @FilePath: \qianmingtian.github.io\code\java\DeleteDomData.java
 */
class ListNode {
    int val;
    ListNode next;

    ListNode(int val) {
        this.val = val;
    }
}

public class DeleteDomData {

    public static void main(String[] args) {

        int[] num = {4};
        ListNode head = new ListNode(num[0]);
        ListNode pre = head;
        for (int i = 1; i < num.length; i++) {
            ListNode node = new ListNode(num[i]);
            pre.next = node;
            pre = node;

        }
        pre = head ;
        while(pre!= null){
            System.out.print(pre.val + "  " );
            pre = pre.next;
        }

        del(head);
        pre = head;
        while (pre != null) {
            System.out.print(pre.val + "  ");
            pre = pre.next;
        }
        // System.out.println(head);
    }

    private static ListNode del(ListNode head) {
        if (head == null)
            return head;
        ListNode value = head;
        ListNode prepre = value;
        ListNode pre = value.next;
        while (value != null && value.next != null) {

            while (pre != null ) {
                if (value.val == pre.val) {
                    prepre.next = pre.next;
                    pre = pre.next;
                } else {

                    pre = pre.next;
                    prepre = prepre.next;
                }
            }
            value = value.next;
            prepre = value;
            pre = value.next;
        }

        return head;

    }

}/*
  * @Author: qianmingtian
  * 
  * @Date: 2020-07-07 17:37:01
  * 
  * @LastEditors: qianmingtian
  * 
  * @LastEditTime: 2020-07-07 17:37:01
  * 
  * @FilePath: \qianmingtian.github.io\code\java\DeleteDomData.java
  */
